import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import { CurrentUserType } from 'src/types/user';
import { PlanService } from './plan.service';
import { CurrentUser } from '../auth/current-user.decorator';

import CreatePlanDto from './dto/create.plan.dto';
import UpdatePlanDto from './dto/update.plan.dto';

@Controller('api')
export class PlanController {
  constructor(private readonly planService: PlanService) {}


  // getPlan
  @Get('getPlans/:planId')
  getMotion(@Param('planId') id: string) {
    return this.planService.getPlan(id);
  }

  @Get('getPlans')
  getPlans(@CurrentUser() user: CurrentUserType) {
    return this.planService.getPlans(user.id);
  }

  @Post('addPlan')
  async addPlan(
    @CurrentUser() user: CurrentUserType,
    @Body() data: CreatePlanDto,
  ) {
    return this.planService.createPlan(user.id, data);
  }

  @Post('deletePlan')
  deletePlan(@Body('planId') id: string) {
    return this.planService.deletePlan(id);
  }

  @Post('updatePlan')
  updatePlan(@Body() data: UpdatePlanDto) {
    return this.planService.updatePlan(data._id, data);
  }
}
